<template>
	<view>
		<view style="margin-top: 20px;"></view>
		<button @click="blue">巡检装置</button>
		<button @click="xinxi">所有车辆信息</button>
		<button @click="entry">电池信息录入</button>
		<button @click="look">电池信息查看</button>
		<button @click="history">骑行历史</button>
		<button @click="back" v-if="use==1">还车</button>
		<button @click="logout">退出登陆</button>
	</view>
</template>

<script>
	import store from '@/store/index.js'; //需要引入store
	export default {
		data() {
			return {
				
			}
		},
		computed: {
			useCarId() {
				return store.state.useCarId
			},
			use() {
				return store.state.user.use
			},
			account() {
				return store.state.user.account
			}
		},

		watch: {
			useCarId: {
				deep: true,
				handler(newval, oldval) {
					this.useCarId = newval
				}
			},
			use: {
				deep: true,
				handler(newval, oldval) {
					this.use = newval
				}
			},
			account: {
				deep: true,
				handler(newval, oldval) {
					this.account = newval
				}
			}
		},

		methods: {
			entry() {
				uni.navigateTo({
					url: '../enrty/enrty'
				})
			},
			look() {
				uni.navigateTo({
					url: '../look/look'
				})
			},
			xinxi() {
				uni.navigateTo({
					url: '../query/query'
				})
			},
			history() {
				uni.navigateTo({
					url: '../history/history'
				})
			},
			back() {
				var time = new Date().getTime()
				console.log(time);
				store.commit("setETime",time)
				uni.request({
					url: 'http://172.20.10.5:8080/user/return',
					header: {
						'content-type': 'application/json',
					},
					data: {
						userAccount: this.account,
						startTime: store.state.sTime,
						endTime: time,
						carId: this.useCarId
					},
					method:'POST',
					success(res) {
						console.log(res);
						store.commit("setUserUse", 0)
						store.commit("setUseCarId", '')
						store.commit("setETime", time)
						uni.showToast({
							title: '还车成功'
						})
					},
					fail(res) {
						console.log(res);
						uni.showToast({
							title: '还车失败'
						})
					}
				})
			},
			blue() {
				uni.navigateTo({
					url: '../xunjian/xunjian'
				})
			},
			ucharts() {
				uni.navigateTo({
					url: '../ucharts/ucharts'
				})
			},
			logout() {
				console.log('退出登陆')
				store.commit("setIsLogin", 0)
				uni.navigateTo({
					url: '../index/index'
				})
			}
		}
	}
</script>

<style>
	button {
		margin-bottom: 20rpx;
	}
</style>
